package com.k1ccc0.alumniinformationmanagement.controller;

import com.k1ccc0.alumniinformationmanagement.pojo.Activity;
import com.k1ccc0.alumniinformationmanagement.pojo.PageBean;
import com.k1ccc0.alumniinformationmanagement.pojo.Result;
import com.k1ccc0.alumniinformationmanagement.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@Slf4j
@RestController
@CrossOrigin
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @GetMapping("/NoticeNameAndTime")
    public Result generateNoticeList(){
        List<Activity> actList = activityService.generateNoticeList();
        return Result.success(actList);
    }

    @GetMapping("/SActNameAndTime")
    public Result generateSActList(){
        List<Activity> sActList = activityService.generateSActList();
        return Result.success(sActList);
    }

    @GetMapping("/DActNameAndTime")
    public Result generateDActList(){
        List<Activity> DActList = activityService.generateDActList();
        return Result.success(DActList);
    }

    @PostMapping("/Act/ActPublish")
    public Result activityUpload(@RequestBody Activity activity){
        log.info("上传新活动:{}",activity);
        activityService.activityUpload(activity);
        return Result.success();
    }


    @GetMapping("/ActDetail/{id}")
    public Result generateActDetail(@PathVariable Integer id){
        Activity actDetail = activityService.generateActDetail(id);
        return Result.success(actDetail);
    }
    @GetMapping("/Act/ActList")
    public Result selectActByPage(@RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer pageSize,
                                  String name, String publisher,String type,
                                  @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                  @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        log.info("分页查询，参数:{},{},{},{},{},{}",page,pageSize,name,publisher,begin,end);
        PageBean pageBean = activityService.selectActByPage(page, pageSize, name, publisher,type,begin, end);
        return Result.success(pageBean);
    }

    @PostMapping("/Act/DeleteById")
    public Result deleteById(@RequestBody List<Integer> ids){
        log.info("批量删除:{}",ids);
        activityService.deleteById(ids);
        return Result.success();
    }


}
